package com.cdh.vod.controller.api;

import com.cdh.base.DIYException;
import com.cdh.base.util.ExceptionUtils;
import com.cdh.utils.result.Restful;
import com.cdh.utils.result.ResultCodeEnum;
import com.cdh.vod.service.VodService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author by cdh
 * @description:
 * @Date: Created in 20:15 on 2021/2/27
 */
@Api(value = "阿里云视频点播")
@RestController
@RequestMapping("api/vod/media")
@CrossOrigin
@Slf4j
public class MediaController {

    @Autowired
    private VodService vodService;

    @GetMapping("get-play-auth/{videoSourceId}")
    public Restful getPlayAuth(
            @ApiParam(value = "阿里云视频文件的id",required = true)
            @PathVariable String videoSourceId
    ){
        try{
            String playAuth = vodService.getPlayAuth(videoSourceId);
            return Restful.ok().message("获取播放凭证成功").data("playAuth",playAuth);
        }catch (Exception e){
            log.error(ExceptionUtils.getMessage(e));
            throw new DIYException(ResultCodeEnum.FETCH_PLAYAUTH_ERROR.getCode(),
                    ResultCodeEnum.FETCH_PLAYAUTH_ERROR.getMessage());
        }
    }

}
